package com.bby.screentool.base;

import android.content.Context;

import com.bby.screentool.event.Action;
import com.google.gson.Gson;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONObject;

public class Config {
    public static final String SERVER_IP = "192.168.105.243";
    public static final String SERVER_PORT = "9999";
    public static final String URL_SCREEN_CHECK = String.format("http://%s:%s/screen/check",SERVER_IP,SERVER_PORT);;
    public static final String URL_SCREEN_CONFIG = String.format("http://%s:%s/screen/config",SERVER_IP,SERVER_PORT);;
    public static final String KEY = "zmnxcksldlngntuy3jj5n2omapir";
    public static final int SOCKET_PORT = 8888;//redir add tcp:55555:55555
    public static int DEFAULT_TIMEOUT = 5000;
    public static final String TARGET_ID_KEY = "TARGET_ID_KEY";

    // 可以在线设置
    public static String STUN = "stun:stun.callwithus.com:3478";//穿透服务器 101.35.10.133

    public static final int VIDEO_FPS = 30;

    public static void init(Context context) {
        new Thread(()->{
            HttpResponse response = HttpRequest.get(Config.URL_SCREEN_CONFIG)
                    .header("token", Config.KEY)
                    .timeout(Config.DEFAULT_TIMEOUT)
                    .execute();
            if (!response.isOk()) {
                return;
            }
            Action action = new Gson().fromJson(response.body(), Action.class);
            JSONObject d = new JSONObject(action.getData());
            STUN = d.getStr("SERVER_IP",STUN);
            DEFAULT_TIMEOUT = d.getInt("SERVER_IP",DEFAULT_TIMEOUT);
        }).start();

    }
}
